package thread;

class Counter{
    static int count;
    //synchronized 可以修饰代码块也可以修饰方法
    synchronized public void increase1(){
        count++;
    }
    public void increase2(){
        synchronized (this){
            count++;
        }
    }
    synchronized public static void increase3(){
        count++;
    }
    public static void increase4(){
        synchronized (Counter.class){
            count++;
        }
    }
}
public class demo4 {

    public static void main(String[] args) throws InterruptedException {
        Counter counter = new Counter();
        Thread t1 = new Thread(()->{
            for(int i = 0;i<5000;i++){
                counter.increase1();
            }
        });

        Thread t2 = new Thread(()->{
            for(int i = 0;i<5000;i++){
                counter.increase1();
            }
        });
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println(Counter.count);
    }
}
